//
//  HRTopicInfoViewController.m
//  Hear
//
//  Created by mac on 2018/1/15.
//  Copyright © 2018年 mac. All rights reserved.
// 从足迹全部话题进入留声机

#import "HRTopicInfoViewController.h"
#import "UIButton+SSEdgeInsets.h"
#import "HRRecordAudioViewController.h"
#import "HRHearCollectionViewCell.h"
#import "RFLayout.h"
#import "HRMainViewModel.h"
#import "EmitterBtn.h"
#import "DOUAudioStreamer.h"
#import "Track.h"
#import "HRSearchToolView.h"
#import "HRDynamicViewController.h"
#import "HRFollowDyanmicInfoViewController.h"

static palyTag = 0;

static void *kStatusKVOKey = &kStatusKVOKey;
static void *kDurationKVOKey = &kDurationKVOKey;
static void *kBufferingRatioKVOKey = &kBufferingRatioKVOKey;
@interface HRTopicInfoViewController ()<UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic,strong)UIView *headView;
@property(nonatomic, strong)UICollectionView *myCollectionView;
@property(nonatomic, strong)NSMutableArray *contentArray;
@property(nonatomic, strong)HRMainViewModel *mainViewModel;
@property (nonatomic, assign)NSInteger pIndex;
@property(nonatomic, strong)UIButton *closeButton;
@property(nonatomic, strong)UIButton *messageButton;
@property(nonatomic, strong)EmitterBtn *likeButton;
@property(nonatomic, strong)UILabel *distanceLabel;
@property(nonatomic, strong)UIView *bottomView;
@property(nonatomic, strong)UIButton *nickNameLabel;
@property(nonatomic, strong)UILabel *lineCoundLabel;
@property(nonatomic, strong)HRMainRootModel *currentModel;
@property (nonatomic) NSInteger currentIndex;
@property(nonatomic, strong)DOUAudioStreamer *streamer;
@property(nonatomic, assign)int SortType;
@property(nonatomic, assign)int Sex;
@property(nonatomic, strong)UIImageView *blankImageView;
@property(nonatomic, strong)UIButton *nextButton;
@property(nonatomic, strong)UIButton *playButton;
@end

@implementation HRTopicInfoViewController
#pragma mark - Get and Set
- (UIButton *)nextButton {
    if (_nextButton == nil) {
        _nextButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.width-80, self.headView.bottom+30, 60, 30)];
        _nextButton.hidden = YES;
        [_nextButton addTarget:self action:@selector(nextClick) forControlEvents:UIControlEventTouchUpInside];
        [_nextButton setTitle:@"换一批" forState:0];
        [_nextButton setTitleColor:BlueColor forState:0];
        _nextButton.titleLabel.font = CustomUIFont(15);
    }
    return _nextButton;
}


- (UIImageView *)blankImageView{
    if (_blankImageView == nil) {
        _blankImageView = [[UIImageView alloc] init];
        _blankImageView.image = [UIImage imageNamed:@"没有此话题用户的状态下"];
        [self.view addSubview:self.blankImageView];
        _blankImageView.userInteractionEnabled = YES;
        _blankImageView.hidden = YES;
        WeakSelf
        [self.blankImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(adjuctFloat(230), adjuctFloat(170)));
            make.centerX.equalTo(weakSelf.view);
            make.top.equalTo(weakSelf.myCollectionView.mas_centerY);
        }];
    }
    return _blankImageView;
}


- (HRMainViewModel *)mainViewModel{
    if (_mainViewModel == nil) {
        _mainViewModel = [[HRMainViewModel alloc] init];
    }
    return _mainViewModel;
}

- (NSMutableArray *)contentArray{
    if (_contentArray == nil) {
        _contentArray = [[NSMutableArray alloc] init];
    }
    return _contentArray;
}

- (UICollectionView *)myCollectionView{
    if (_myCollectionView == nil) {
        WeakSelf
        RFLayout *layout = [RFLayout new];
        layout.trangeScaleMaxBlock = ^(NSInteger index) {
            weakSelf.currentIndex = index;
            [weakSelf createPlayer];
            if (palyTag != 0) {
                [self streamPlay];
            }
            
        };
        _myCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, self.nextButton.bottom, kFullWidth, CGHeightMT(130)) collectionViewLayout:layout];
        _myCollectionView.backgroundColor = [UIColor whiteColor];
        _myCollectionView.delegate = self;
        _myCollectionView.dataSource = self;
        _myCollectionView.showsVerticalScrollIndicator = NO;
        _myCollectionView.showsHorizontalScrollIndicator = NO;
        _myCollectionView.contentInset = UIEdgeInsetsMake(0, (kFullWidth-80)/2, 0, (kFullWidth-80)/2);
        
    }
    return _myCollectionView;
}

- (UIView *)bottomView{
    if (_bottomView == nil) {
        _bottomView = [[UIView alloc] init];
        [self.view addSubview:self.bottomView];
        _bottomView.hidden = YES;
        _nickNameLabel = [[UIButton alloc] init];
        [_nickNameLabel setTitleColor:MainColor forState:0];
        _nickNameLabel.titleLabel.font = CustomUIFont(15);
        _nickNameLabel.titleLabel.textAlignment = 1;
        _nickNameLabel.userInteractionEnabled = YES;
        WeakSelf
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
            [weakSelf lookUserInfo];
        }];
        [_nickNameLabel addGestureRecognizer:tap];
        [self.bottomView addSubview:self.nickNameLabel];
        
        
        
        
        self.distanceLabel = [UILabel new];
        self.distanceLabel.font = CustomUIFont(14);
        self.distanceLabel.textColor = FirstTextColor;
        [self.bottomView  addSubview:self.distanceLabel];
        self.distanceLabel.textAlignment = 1;
        [self.distanceLabel sizeToFit];
        
        
        self.playButton = [UIButton buttonWithType:0];
        [self.playButton setImage:[UIImage imageNamed:@"动画0"] forState:0];
        [self.playButton addTarget:self action:@selector(targetPlayButton) forControlEvents:UIControlEventTouchUpInside];
        [self.bottomView addSubview:self.playButton];
        NSArray *animateNames = @[@"动画0",@"动画1",@"动画2"];
        NSMutableArray * animationImages = [[NSMutableArray alloc] initWithCapacity:animateNames.count];
        for (NSString * animateName in animateNames) {
            UIImage * animateImage = [UIImage imageNamed:animateName];
            [animationImages addObject:animateImage];
        }
        self.playButton.imageView.animationImages = animationImages;
        self.playButton.imageView.animationDuration = 0.7;

        
        
        
        self.closeButton = [UIButton buttonWithType:0];
        [self.closeButton setImage:[UIImage imageNamed:@"hear_屏蔽"] forState:0];
        [self.closeButton addTarget:self action:@selector(closeButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bottomView addSubview:self.closeButton];
        [self.closeButton setTitleColor:FirstTextColor forState:0];
        self.closeButton.titleLabel.font = CustomUIFont(13);
        
        self.messageButton = [UIButton buttonWithType:0];
        [self.messageButton setImage:[UIImage imageNamed:@"hear_打招呼"] forState:0];
        [self.messageButton addTarget:self action:@selector(messageButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bottomView addSubview:self.messageButton];
        
        self.likeButton = [EmitterBtn buttonWithType:0];
        [self.likeButton setImage:[UIImage imageNamed:@"hear_点赞"] forState:0];
        [self.likeButton setImage:[UIImage imageNamed:@"hear_点赞-选中"] forState:UIControlStateSelected];
        [self.likeButton setImage:[UIImage imageNamed:@"hear_点赞-选中"] forState:UIControlStateHighlighted];
        [self.likeButton setImageEdgeInsets:UIEdgeInsetsMake(-7, -7, 0, 7)];
        [self.likeButton addTarget:self action:@selector(likeButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bottomView addSubview:self.likeButton];
        [self.likeButton setTitleColor:FirstTextColor forState:0];
        self.likeButton.titleLabel.font = CustomUIFont(13);
        CGFloat likeTopPaidng;
        if(kFullWidth == 320){
            likeTopPaidng = adjuctFloat(10);
        }else{
            likeTopPaidng = adjuctFloat(30);
        }
        self.likeButton.frame = CGRectMake(kScreenWidth/2+65, 40+likeTopPaidng+5, 50, 50);
        
        
        self.lineCoundLabel = [UILabel new];
        self.lineCoundLabel.font = CustomUIFont(13);
        self.lineCoundLabel.textColor = FirstTextColor;
        [self.bottomView  addSubview:self.lineCoundLabel];
        self.lineCoundLabel.frame = CGRectMake(self.likeButton.left-7, self.likeButton.bottom-20, self.likeButton.width, 20);
        self.lineCoundLabel.textAlignment = 1;
        
        [_bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(kFullWidth, adjuctFloat(210)));
            make.top.equalTo(weakSelf.view).offset(_myCollectionView.bottom);
            make.left.equalTo(weakSelf.view);
        }];
        
        
        
        [_nickNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.bottomView);
            make.height.equalTo(@20);
            make.width.equalTo(@180);
            make.centerX.equalTo(weakSelf.view);
        }];
        
        
        
        
        [self.distanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(weakSelf.view);
            make.top.equalTo(_nickNameLabel.mas_bottom);
            make.size.mas_equalTo(CGSizeMake(100, 30));
        }];
        
//        [self.playButton mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.equalTo(weakSelf.distanceLabel);
//            make.left.equalTo(weakSelf.distanceLabel.mas_right);
//            make.size.mas_equalTo(CGSizeMake(30, 30));
//        }];
        
        [self.playButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(weakSelf.view);
            make.top.equalTo(_nickNameLabel.mas_bottom).offset(15 * scaleHeight);
            make.size.mas_equalTo(CGSizeMake(30, 30));
        }];
        
        [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakSelf.view.mas_centerX).offset(-60);
            if(kFullWidth == 320){
                make.top.equalTo(weakSelf.distanceLabel.mas_bottom).offset(adjuctFloat(10));
            }else{
                make.top.equalTo(weakSelf.distanceLabel.mas_bottom).offset(adjuctFloat(30));
            }
            make.size.mas_equalTo(CGSizeMake(50, 50));
        }];
        
        
        [self.messageButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(weakSelf.view.mas_centerX);
            make.top.equalTo(weakSelf.closeButton.mas_top);
            make.size.mas_equalTo(CGSizeMake(50, 50));
        }];
        
        //        [self.likeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        //            make.left.equalTo(weakSelf.messageButton.mas_right).offset(40);
        //            make.top.equalTo(weakSelf.closeButton.mas_top);
        //            make.size.mas_equalTo(CGSizeMake(50, 50));
        //        }];
    }
    return _bottomView;
}

- (UIView *)headView{
    if (_headView == nil) {
        _headView = [[UIView alloc] initWithFrame:CGRectMake(20, kTopHeight+40, kScreenWidth-40, 150)];
        
        UIView *showView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _headView.width, _headView.height-30)];
        [_headView addSubview:showView];
        
        UILabel *contentLabel = [UILabel new];
        contentLabel.text = self.model.QuestionText;
        contentLabel.font = CustomUIFont(13);
        contentLabel.textColor = FirstTextColor;
        [showView  addSubview:contentLabel];
        contentLabel.numberOfLines = 0;
        contentLabel.textAlignment = 1;
        contentLabel.frame = CGRectMake(20, 0, _headView.width-40, _headView.height-30);
        
        showView.backgroundColor = [UIColor whiteColor];
        showView.layer.shadowColor = [UIColor blackColor].CGColor;
        showView.layer.shadowRadius      = 3;
        showView.layer.shadowOpacity     = 0.2;
        showView.layer.shadowOffset      = CGSizeMake(1, 1);
        showView.layer.shadowPath        = [UIBezierPath bezierPathWithRect:showView.bounds].CGPath;
        
        UIButton *answerButton = [UIButton buttonWithType:0];
        [answerButton setImage:[UIImage imageNamed:@"答"] forState:0];
        [answerButton addTarget:self action:@selector(answerButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [_headView addSubview:answerButton];
        answerButton.frame = CGRectMake((_headView.width-55)/2, showView.bottom-55/2, 55, 55);
    }
    return _headView;
}



- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self setupView];
    
    NSInteger hear_selectSex = [[NSUserDefaults standardUserDefaults] integerForKey:@"hear_selectSex"];
    NSInteger hear_selectSortType = [[NSUserDefaults standardUserDefaults] integerForKey:@"hear_selectSortType"];
    
    if (hear_selectSex == 1){
        self.Sex = 2;
    }else if (hear_selectSex == 2){
        self.Sex = 1;
    }else if (hear_selectSex == 3){
        self.Sex = 0;
    }
    self.SortType = hear_selectSortType;
    
    [self getContentPeopel];
    // Do any additional setup after loading the view.
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.contentArray.count;
}

- (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    HRHearCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"hearIdentifier" forIndexPath:indexPath];
    cell.model = self.contentArray[indexPath.row];
    WeakSelf
    cell.clickIconBlock = ^(){
        weakSelf.currentIndex = indexPath.row;
        [weakSelf lookUserInfo];
    };
    cell.clickNickNameBlock = ^(){
        weakSelf.currentIndex = indexPath.row;
        [weakSelf createPlayer];
        [weakSelf.streamer play];
    };
    
    
    return cell;
}

#pragma mark 播放按钮
- (void)targetPlayButton{
    ++palyTag;
    self.playButton.selected = !self.playButton.isSelected;
    if (self.playButton.selected){// 播放
//        self.currentPlayStatus = YES;
        [self.playButton.imageView startAnimating];
        if (self.streamer){
            [self.streamer play];
        }else{
            [self createPlayer];
            [self.streamer play];
        }
    }else{//暂停
        [self.streamer pause];
        [self.playButton.imageView stopAnimating];
//        self.currentPlayStatus = NO;
    }
}

#pragma mark -----音频播放
-(void)streamPlay
{
    [self.streamer play];
    [self.playButton.imageView startAnimating];
}

#pragma mark -----停止音频播放
-(void)streamPause
{
    [self.streamer pause];
    [self.playButton.imageView stopAnimating];
}

- (void)createPlayer{
    self.currentModel = self.contentArray[self.currentIndex];
    [self setupContentData];
    
    Track *track = [[Track alloc] init];
    track.audioFileURL = [NSURL URLWithString:self.currentModel.SoundUrl];
    @try {
        [self removeStreamerObserver];
    } @catch(id anException){
    }
    
    _streamer = nil;
    _streamer = [DOUAudioStreamer streamerWithAudioFile:track];
    
    [self addStreamerObserver];
//    [self.streamer play];
}

- (void)removeStreamerObserver {
    [_streamer removeObserver:self forKeyPath:@"status"];
    [_streamer removeObserver:self forKeyPath:@"duration"];
    [_streamer removeObserver:self forKeyPath:@"bufferingRatio"];
}

- (void)addStreamerObserver {
    [_streamer addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:kStatusKVOKey];
    [_streamer addObserver:self forKeyPath:@"duration" options:NSKeyValueObservingOptionNew context:kDurationKVOKey];
    [_streamer addObserver:self forKeyPath:@"bufferingRatio" options:NSKeyValueObservingOptionNew context:kBufferingRatioKVOKey];
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
    if (context == kStatusKVOKey) {
        [self performSelector:@selector(updateStatus)
                     onThread:[NSThread mainThread]
                   withObject:nil
                waitUntilDone:NO];
    } else if (context == kDurationKVOKey) {
        [self performSelector:@selector(updateSliderValue:)
                     onThread:[NSThread mainThread]
                   withObject:nil
                waitUntilDone:NO];
    } else if (context == kBufferingRatioKVOKey) {
        [self performSelector:@selector(updateBufferingStatus)
                     onThread:[NSThread mainThread]
                   withObject:nil
                waitUntilDone:NO];
    } else {
        [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
    }
}

- (void)updateBufferingStatus {
    
}

- (void)updateSliderValue:(id)timer{
    
}
- (void)_cancelStreamer{
    if (_streamer !=nil) {
        [_streamer pause];
        [_streamer removeObserver:self forKeyPath:@"status"];
        [_streamer removeObserver:self forKeyPath:@"duration"];
        [_streamer removeObserver:self forKeyPath:@"bufferingRatio"];
        _streamer =nil;
    }
}

- (void)updateStatus {
    switch ([_streamer status]) {
        case DOUAudioStreamerPlaying:
//            self.musicIsPlaying = YES;
//            self.playButton.selected = YES;
//            [self.playButton.imageView startAnimating];
            break;
            
        case DOUAudioStreamerPaused:
            self.playButton.selected = NO;
            [self.playButton.imageView stopAnimating];
            break;
            
        case DOUAudioStreamerIdle:
            break;
            
        case DOUAudioStreamerFinished:
            self.playButton.selected = NO;
            [self.playButton.imageView stopAnimating];
            [self.playButton setImage:[UIImage imageNamed:@"动画0"] forState:0];
            [self _cancelStreamer];
            break;
            
        case DOUAudioStreamerBuffering:
            break;
            
        case DOUAudioStreamerError:
            break;
    }
}



-(void)dealloc{
    self.streamer = nil;
}
-(void)viewWillDisappear:(BOOL)animated{
    [self removeStreamerObserver];
    [self.streamer pause];
    self.streamer = nil;
    [super viewWillDisappear:animated];
}

- (void)setupView{
    UIButton *titileButton = [UIButton buttonWithType:0];
    titileButton.size = CGSizeMake(100, 30);
    [titileButton setImage:[UIImage imageNamed:@"hear_search"] forState:0];
    [titileButton setTitle:self.model.ParentQuestionText forState:0];
    [titileButton setImagePositionWithType:SSImagePositionTypeRight spacing:2];
    [titileButton setTitleColor:[UIColor whiteColor] forState:0];
    titileButton.titleLabel.font = CustomUIFont(17);
    [titileButton addTarget:self action:@selector(titileButtonClick) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.titleView = titileButton;
    
    
    [self.view addSubview:self.headView];
    
    [self.myCollectionView registerNib:[UINib nibWithNibName:@"HRHearCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"hearIdentifier"];
    [self.view addSubview:self.nextButton];
    
    [self.view addSubview:self.myCollectionView];
    
    [self.view addSubview:self.bottomView];
    
    [self.view addSubview:self.blankImageView];
}

- (void)titileButtonClick{
    WeakSelf
    [HRSearchToolView showSearchToolView:^(NSDictionary *contentDict) {
        weakSelf.Sex = [contentDict[@"Sex"] intValue];
        weakSelf.SortType = [contentDict[@"SortType"] intValue];
        weakSelf.pIndex = 0;
//        weakSelf.topView.currentIndex = 0;
//        weakSelf.QuestionID = 0;
//        weakSelf.currentIndex = 0;
        //        [weakSelf.topView.tableView scrollToRow:0 inSection:0 atScrollPosition:UITableViewScrollPositionTop animated:YES];
//        [weakSelf getContentPeopel:YES andFromSearch:YES];
//        weakSelf.fromSearchPage = weakSelf.currentAnswerPage;
        [self getContentPeopel];
        [MobClick event:@"Hearer1"];
        
    }];
}

- (void)nextClick{
    [self.streamer pause];
    self.pIndex ++;
    if (!self.contentArray.count){
        self.pIndex = 0;
    }
    [self getContentPeopel];
}

- (void)answerButtonClick{
    [MobClick event:@"Hearer2"];
    HRRecordAudioViewController *recordVC = [HRRecordAudioViewController new];
    recordVC.isSound = YES;
    recordVC.title = @"我来回答";
//    recordVC.QuestionID = self.model.QuestionID;
    recordVC.soundRemendText = self.model.QuestionText;
    [self.navigationController pushViewController:recordVC animated:YES];
}

- (void)getContentPeopel{
    WeakSelf
    HRMainRootRequestModel *requestModel = [HRMainRootRequestModel new];
    requestModel.PageSize = @"50";
    requestModel.PageIndex = self.pIndex;
    requestModel.CurrentUserLocalId = USERID;
    requestModel.Sex = self.Sex;
    requestModel.SortType = self.SortType;
    requestModel.StartAge = @"18";
    requestModel.EndAge = @"50";
    requestModel.QuestionPageIndex = @"0";
    requestModel.QuestionPageSize = @"1000";
    requestModel.QuestionID = self.model.QuestionID;
    requestModel.ParentQuestionID = self.model.ParentQuestionID;
    [self.mainViewModel getMainContentParam:requestModel resultArr:^(NSArray *resultArr) {
        [MBProgressHUD hideHUDForView:WINDOW animated:YES];

//        if (!resultArr.count){
//            
//        }

        dispatch_async(dispatch_get_main_queue(), ^{
            HRMainRootModel *model = [resultArr firstObject];
            if (model.ListSoundArr.count){
                weakSelf.currentModel = [model.ListSoundArr firstObject];
                [weakSelf setupContentData];
                weakSelf.blankImageView.hidden = YES;
                weakSelf.bottomView.hidden = NO;
                weakSelf.nextButton.hidden = NO;
            }else{
//                weakSelf.nextButton.hidden = YES;
                weakSelf.blankImageView.hidden = NO;
                weakSelf.bottomView.hidden = YES;
                weakSelf.pIndex = 0;
                [weakSelf.contentArray removeAllObjects];
//                static dispatch_once_t onceToken;
//                dispatch_once(&onceToken, ^{
//                    weakSelf.pIndex = 0;
//                    [weakSelf getContentPeopel];
//                });

            }
            [weakSelf.contentArray addObjectsFromArray:model.ListSoundArr];
            [weakSelf.myCollectionView reloadData];
        });
    }];
}

- (void)setupContentData{
    
    if ([_currentModel.UserLocalId isEqualToString:USERID]){
        self.closeButton.enabled = NO;
        self.messageButton.enabled = NO;
    }else{
        self.closeButton.enabled = YES;
        self.messageButton.enabled = YES;
    }
    
    [self.nickNameLabel setTitle:[NSString stringWithFormat:@"%@",self.currentModel.UserGroup] forState:0];
    NSDictionary *dic = @{NSFontAttributeName:self.nickNameLabel.titleLabel.font};//指定字号
    CGFloat nickNameLabelWidth = [self.nickNameLabel.titleLabel.text boundingRectWithSize:CGSizeMake(self.view.width - 30, 0)/*计算高度要先指定宽度*/ options:NSStringDrawingUsesLineFragmentOrigin |
                                  NSStringDrawingUsesFontLeading attributes:dic context:nil].size.width;
    [self.nickNameLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(nickNameLabelWidth+22);
    }];
    
    if ([self.currentModel.Sex intValue] ==1){
        [self.nickNameLabel setImage:[UIImage imageNamed:@"nim_male"] forState:0];
    }else{
        [self.nickNameLabel setImage:[UIImage imageNamed:@"nim_female"] forState:0];
    }
    [self.nickNameLabel setImagePositionWithType:SSImagePositionTypeRight spacing:2];
    self.distanceLabel.text = self.currentModel.ActiveText;
    
    self.likeButton.selected = [self.currentModel.IsDoLike intValue];
    self.lineCoundLabel.text = self.currentModel.LikeCount;
    //    [self.likeButton setTitle:self.currentModel.LikeCount forState:0];
    //    [self.likeButton setImagePositionWithType:SSImagePositionTypeTop spacing:0];
    
    [self.closeButton setTitle:self.currentModel.CommentCount forState:0];
    [self.closeButton setImagePositionWithType:SSImagePositionTypeTop spacing:0];
    
    //    self.likeButton.enabled = [self.currentModel.IsDoLike intValue];
    
    self.nickNameLabel.imageView.size = CGSizeMake(20, 20);
    WeakSelf
    
//    [self.leftLineLabel mas_updateConstraints:^(MASConstraintMaker *make) {
//        make.right.equalTo(weakSelf.distanceLabel.mas_left);
//    }];
//
//    [self.rightLineLabel mas_updateConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(weakSelf.distanceLabel.mas_right);
//    }];
}

- (void)likeButtonClick{
    if (self.likeButton.selected) return;
    
    self.likeButton.selected = !self.likeButton.isSelected;
    [self.likeButton starAmimation];
    
    NSMutableDictionary *paramDict = [NSMutableDictionary dictionary];
    paramDict[@"MomentLocalId"] = self.currentModel.MomentLocalId;
    paramDict[@"LocalId"] = self.currentModel.LocalId;
    paramDict[@"UserLocalId"] = USERID;
    paramDict[@"CreateTime"] = [self getCurrentTime];
    
    WeakSelf
    [self.mainViewModel postSaveSoundLike:paramDict isSeccess:^(BOOL isSeccess) {
        if (isSeccess){
            weakSelf.currentModel.IsDoLike = @"1";
            weakSelf.likeButton.selected = YES;
            weakSelf.lineCoundLabel.text = [NSString stringWithFormat:@"%d",[self.lineCoundLabel.text intValue]+1];
        }
    }];
    
}

- (void)closeButtonClick{
    if (!self.currentModel.MomentLocalId.length) return;
    WeakSelf
    HRFollowDyanmicInfoViewController *infoVC = [HRFollowDyanmicInfoViewController new];
    infoVC.dynamicID = self.currentModel.MomentLocalId;
    [self.navigationController pushViewController:infoVC animated:YES];
    
}

- (void)messageButtonClick{
    [MobClick event:@"Hearer3"];
    EaseMessageViewController *messgaeVC = [[EaseMessageViewController alloc] initWithConversationChatter:self.currentModel.UserLocalId conversationType:EMConversationTypeChat];
    messgaeVC.otherNickNameStr = self.currentModel.NickName;
    messgaeVC.otherIconStr = self.currentModel.UserPictureBackgroundColor;
    messgaeVC.otherIconName = self.currentModel.UserPictureName;
    messgaeVC.title = self.currentModel.NickName;
    messgaeVC.isSayHello = YES;
    [self.navigationController pushViewController:messgaeVC animated:YES];
    //    }
}


- (void)lookUserInfo{
    if (self.contentArray.count){
        HRMainRootModel *model = self.contentArray[self.currentIndex];
        HRDynamicViewController *infoVC = [HRDynamicViewController new];
        infoVC.currentUserID = model.UserLocalId;
        [self.navigationController pushViewController:infoVC animated:YES];
    }
    
}

- (NSString *)getCurrentTime
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss"];
    return [formatter stringFromDate:[NSDate date]];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
